<?php

namespace app\admin\controller;

use think\facade\View;
use think\Request;
use app\common\controller\Common;
use think\facade\Db;

/**
 * 系统设置控制器
 * Class Set
 * @package app\admin\controller
 */
class Clean extends Common
{
    /**
     * 评价设置
     * @return string
     */
    public function index()
    {
        $user_auth_switch = goalong_hook('user_auth_switch',[],1);
        $wechat_auth_switch = goalong_hook('wechat_auth_switch',[],1);
        $user_switch = $user_auth_switch || $wechat_auth_switch ;

        View::assign('user_switch',$user_switch);

        return View::fetch();
    }

    public function all()
    {
        Db::name('im_visitors')->where(1)->delete();
        Db::name('im_visitors_info')->where(1)->delete();
        Db::name('im_record')->where(1)->delete();

        return json(['code' => 200, 'data' => '操作成功']);
    }

    public function user()
    {
        $sql = "DELETE t1,t2 FROM we_im_visitors AS t1 LEFT JOIN we_im_visitors_info AS t2 ON t1.id=t2.vsid WHERE t1.uid='0'";
        Db::query($sql);
        //
//        Db::name('im_visitors')->where(['uid'=>0])->delete();
//        Db::name('im_visitors_info')->where(1)->delete();

        return json(['code' => 200, 'data' => '操作成功']);
    }

    // 会员清空
    public function users()
    {

        //
        Db::name('im_visitors')->where('uid','>',0)->update(['is_act'=>0]);
//        Db::name('im_visitors_info')->where(1)->delete();

        return json(['code' => 200, 'data' => '操作成功']);
    }
    // 会员记录清空
    public function users_record()
    {
        $sql = "DELETE t1 FROM we_im_record AS t1 ,we_im_visitors AS t2  WHERE t2.uid <> '0' AND "
            ." ( t1.send=t2.id OR t1.receive = t2.id ) ";
        Db::query($sql);
        //Db::name('im_visitors')->where(1)->delete();
        //Db::name('im_visitors_info')->where(1)->delete();

        return json(['code' => 200, 'data' => '操作成功']);
    }

    public function record()
    {
        //Db::name('im_record')->where(1)->delete();
        // 游客记录清空
        $sql = "DELETE t1 FROM we_im_record AS t1 ,we_im_visitors AS t2  WHERE t2.uid = '0' AND "
            ." ( t1.send=t2.id OR t1.receive = t2.id ) ";
        Db::query($sql);

        return json(['code' => 200, 'data' => '操作成功']);
    }

}
